﻿<%@ Page Title="" Language="C#" MasterPageFile="~/SIPO.master" AutoEventWireup="false" CodeFile="recSubSectorlist.aspx.cs" Inherits="SIPO.Web.Lists.Administration.Catalog.recSubSectorlist" %>

<asp:Content ID="ctnBody" ContentPlaceHolderID="body" runat="server">
    <link type="text/css" rel="stylesheet" href="<%= ResolveUrl("~/styles/ui.jqgrid.css") %>" />
    <script type="text/javascript" src="<%= ResolveUrl("~/scripts/i18n/grid.locale-id.js") %>"></script>
    <script type="text/javascript" src="<%= ResolveUrl("~/scripts/jquery.jqGrid.min.js") %>"></script>
    <script src="<%= ResolveUrl("~/scripts/helper.js") %>" type="text/javascript"></script>
    <div>
       <button id="btnAdd" type="button" onclick="OpenForm('add');">Tambah</button>
        <button id="btnEdit" type="button" onclick="OpenForm('edit');">Ubah</button>
        <button id="btnDelete" type="button" onclick="OpenForm('delete');">Hapus</button>
    </div>
    <br />
    <br />
    <table id="table" class="scroll" cellpadding="0" cellspacing="0">
    </table>
    <div id="pager" class="scroll">
    </div>
    <br />
    <div id="dialog" title="Default dialog">
    </div>
     <script type="text/javascript">

         $("#btnAdd").button({ icons: { primary: "ui-icon-plus"} });
         $("#btnEdit").button({ icons: { primary: "ui-icon-pencil"} });
         $("#btnDelete").button({ icons: { primary: "ui-icon-trash"} });

    </script>
    <script type="text/javascript">

        var handlerUrl = '<%= ResolveUrl("~/AjaxHandler/Administration/Catalog/recSubSectorhandler.ashx") %>';

        $('#table').jqGrid({
            url: handlerUrl + '?method=getdata',
            datatype: 'json',
            colNames: ['ID','Sektor', 'Kode Sub Sektor', 'Nama Sub Sektor','Bank'],
            colModel: [
           		{ name: 'SubSectorID', key : true, hidden: true, index: 'SUBSECTORID', width: 60 },
                { name: 'recSector.SectorName', index: 'recSector.SECTORNAME', width: 400, searchoptions: { sopt: ['eq', 'cn']} },
           		{ name: 'SubSectorCode', index: 'SUBSECTORCODE', align: 'center',width: 200, searchoptions: { sopt: ['eq', 'cn']} },
                { name: 'SubSectorName', index: 'SUBSECTORNAME', align: 'left', width: 500, searchoptions: { sopt: ['eq', 'cn']} },
                { name: 'recBankAccount.BankName', index: 'recBankAccount.BankName', align: 'center', width: 200, searchoptions: { sopt: ['eq', 'cn']} },
           	],
            rowNum: 10,
            id: 'SubSectorID',
            multiselect: true,
            rowList: [5, 10, 15, 20],
            pager: '#pager',
            sortname: 'SUBSECTORCODE',
            sortorder: "asc",
            viewrecords: true,
            jsonReader: { repeatitems: false },
            width: 800,
            height: '100%',
            caption: 'Sub Sektor',
            ajaxGridOptions: { cache: false },
            ondblClickRow: function () {
                OpenForm('edit');
            }
        });

        $("#table").jqGrid('navGrid', '#pager', { edit: false, add: false, del: false, searchtext: 'Search', refreshtext: 'Refresh' },
        {}, {}, {}, { closeOnEscape: true, multipleSearch: true, closeAfterSearch: true });

        function OpenForm(ctl) {

            var formUrl = '<%= ResolveUrl("~/forms/administration/catalog/recSubSectorform.aspx") %>';

            var grid = $('#table');
            var selIds = grid.jqGrid('getGridParam', 'selarrrow'),
                selText = [];
            $.each(selIds, function () {
                selText.push(grid.jqGrid('getCell', this, 'SubSectorID'));
            });

            if (ctl == 'edit') {
             if (selIds.length == 0) {
                     alert('Pilih data yang mau di ubah !');
                }
                else if (selIds.length > 1) {
                    alert('Pilih satu record untuk ubah data.');
                }
                else {

                    $('#dialog').load(formUrl + '?id=' + selText + '&menuId=' + '<%= base.MenuID %>').dialog({ autoOpen: false, modal: true, width: 500, title: 'Ubah Sub Sektor' });
                $("#dialog").dialog('open');
                }
            }
            else if (ctl == 'add') {
                $('#dialog').load(formUrl + '?menuId=' + '<%= base.MenuID %>').dialog({ autoOpen: false, modal: true, width: 500, title: 'Tambah Sub Sektor' });
                $("#dialog").dialog('open');
            }
            else {
                 
                 if (selIds.length == 0)
                    alert('Pilih data yang mau di hapus !');
                else {

                var result = window.confirm('Benar data akan di hapus ?');
                if (result) {

                    var objrecSubSector = new Object();
                    objrecSubSector.SubSectorID = encodeURIComponent(selText);

                    jsonData = JSON.stringify(objrecSubSector);

                    CallAjax('<%= ResolveUrl("~/ajaxhandler/administration/catalog/recSubSectorhandler.ashx") %>', "?method=delete", jsonData);

                    setTimeout("$('#table').trigger('reloadGrid');", 3000);
                }
                }
            }

        }
    
    </script>

</asp:Content>

